﻿using System;
using System.ComponentModel;
using System.Web.UI.WebControls;

using Infrastructure.NetExtensions;

namespace TempEmployees.Web
{
    public abstract class BaseDataDisplay : ABaseUserControl
    {
        [CategoryAttribute("Behavior"),
         DescriptionAttribute("Determines whether control in read only mode"),
         DefaultValueAttribute(false)]
        public virtual bool ReadOnly { get; set; }

        [CategoryAttribute("Behavior"),
         DescriptionAttribute("Determines whether control in enabled"),
         DefaultValueAttribute(true)]
        public virtual bool Enabled
        { 
            get { return EditableControl.Enabled; } 
            set { EditableControl.Enabled = value; } 
        }

        [CategoryAttribute("Accessibility")]
        public virtual short TabIndex 
        {
            get { return EditableControl.TabIndex; }
            set { EditableControl.TabIndex = value; }
        }

        [CategoryAttribute("Layout"),
        DefaultValueAttribute("115px")]
        public virtual string Width
        {
            get { return EditableControl.Width.ToString(); }
            set { EditableControl.Width = Unit.Parse(value); }
        }

        protected static readonly string DISPLAY_NAME = "display_name";
        [CategoryAttribute("misc")]
        public virtual string DisplayName
        {
            set { ViewState.Set(DISPLAY_NAME, value); }
            get { return ViewState.Get<string>(DISPLAY_NAME); }
        }

        protected static readonly string AutoPastBack = "auto_post_back";
        [CategoryAttribute("Behavior"),
         DefaultValueAttribute(true)]
        public virtual bool AutoPostBack
        {
            get;
            set;
        }

        protected static readonly string REQUIRED_FIELD = "required_field";
        [CategoryAttribute("Behavior"),
         DefaultValueAttribute(false)]
        public virtual bool Required
        {
            set { ViewState.Set(REQUIRED_FIELD, value); }
            get { return ViewState.Get<bool>(REQUIRED_FIELD); }
        }

        protected static readonly string VALIDATION_TYPE = "validation_type";
        [CategoryAttribute("Behavior")]
        public virtual string ValidationType
        {
            set { ViewState.Set(VALIDATION_TYPE, value); }
            get { return ViewState.Get<string>(VALIDATION_TYPE); }
        }

        protected virtual WebControl EditableControl { get { return null; } }

        public abstract void Reset();

        public abstract bool IsFilled();

        public abstract bool IsValid();
    }
}
